<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>检查上传文件类型</h1>
<hr>
<div>
    <form name="regForm" action="regok.html" method="post" enctype="multipart/form-data">
        <table>
            <tr>
                <td class="title">上传照片：</td>
                <td><input type="file" id="pic" name="pic"/></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <button type="button" onclick="checkFileType()">检查文件类型</button>
                </td>
            </tr>
        </table>
    </form>
</div>

<script>
    function checkFileType() {
        let f = document.getElementById('pic');
        console.log(f.value);
        let filename = f.value;
        if (!filename || !(filename.endsWith('.jpg') || filename.endsWith('.png') || filename.endsWith('.gif'))) {
            alert('只能上传图片类型！');
            return false;
        }
        console.log('执行上传程序....');
    }
</script>
</body>
</html>